package com.baizhi.entity;

public class Page {
	private Integer pageIndex;//页码  
	private Integer pageSize;//单页显示的记录数
	private Integer totalRows;//总记录数
	private Integer totalPages;//总页数
	public Page() {
		//设置每页显示5行记录
		this(1, 6);
	}
	public Page(Integer pageIndex){
		this(pageIndex,6);
	}
	public Page(Integer pageIndex, Integer pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
	}
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getTotalRows() {
		return totalRows;
	}
	//数据库查询到总行数之后，赋值给此方法时，直接计算出总页数
	public void setTotalRows(Integer totalRows) {
		this.totalRows = totalRows;
		this.totalPages = this.totalRows % this.pageSize == 0 ? this.totalRows / this.pageSize : this.totalRows/this.pageSize+1;
	}
	public Integer getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(Integer totalPages) {
		this.totalPages = totalPages;
	}

	//起始行
	public Integer getBeginIndex(){
		return (this.pageIndex-1)*this.pageSize + 1;
	}
	//结束行
	public Integer getEndIndex(){
		return this.pageIndex*this.pageSize;
	}
	//切换页面
	public boolean getHasProPage(){
		return this.pageIndex>1;
	}
	public boolean getHasNexPage(){
		return this.pageIndex < this.totalPages;
	}
	@Override
	public String toString() {
		return "Page [pageIndex=" + pageIndex + ", pageSize=" + pageSize + ", totalRows=" + totalRows + ", totalPages="
				+ totalPages + "]";
	}
}
